from flask import Flask
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager

from utils.common import show_placeholder, new_or_change, classify_show, status_show, show_admin
from views import index_blu, user_blu, passport_blu, admin_blu
from models import db

# 创建flask应用对象
app = Flask(__name__)

# 加载配置
app.config.from_pyfile("config.ini")
# 创建蓝图
app.register_blueprint(index_blu)
app.register_blueprint(user_blu)
app.register_blueprint(passport_blu, url_prefix='/passport')
app.register_blueprint(admin_blu)

# 初始化数据库
db.init_app(app)
#添加过滤器
app.add_template_filter(show_placeholder)
app.add_template_filter(new_or_change)
app.add_template_filter(classify_show)
app.add_template_filter(status_show)
app.add_template_filter(show_admin)

# 添加数据库迁移等工具
manager = Manager(app)
# 生成migrate对象 用来数据库迁移
migrate = Migrate(app, db)
# 添加db命令
manager.add_command('db', MigrateCommand)

if __name__ == '__main__':
    manager.run()
